<?php

// functon enum  static enum  const   triat
interface Colorer
{
    public function color(): Color;
}

trait Rectangle
{
    public function shape(): string
    {
        return "Rectangle";
    }
}
enum Color: string implements Colorer
{
    use Rectangle;
    case Red = "red";
    case Green = "green";
    case Blue = "blue";

    public const red = self::Red;

    // $this self Color 都可以
    public function color(): self
    {
        return match ($this) {
            static::Red => static::Red,
            static::Green => static::Green,
            static::Blue => static::Blue,
        };
    }

    public static function static_color(string $cm): static
    {
        return match ($cm) {
            "red" => static::Red,
            default => static::Blue,
        };
    }
}

var_dump(Color::cases());
var_dump(Color::static_color("red"));
var_dump(Color::Blue->color()->value);
var_dump(Color::Blue->shape());
var_dump(serialize(Color::Blue));
